package com.mxpio.erp.technology.controller;


import com.mxpio.erp.common.technology.entity.ProdTecRoutProc;
import com.mxpio.erp.common.technology.service.ProdTecRoutProcService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author wupaa
 */
@Tag(name = "ProdTecRoutProcController", description = "产品工艺路线明细信息接口")
@RestController
@RequestMapping("/erp/tech/prodrout/proc/")
public class ProdTecRoutProcController {

    @Autowired
    private ProdTecRoutProcService service;

    @GetMapping("list")
    @Operation(summary = "产品工艺路线明细列表", description = "获取产品工艺路线明细列表（无分页）", method = "GET")
    public Result<List<ProdTecRoutProc>> list(@Parameter(description="查询参数") Criteria criteria) throws UnsupportedEncodingException {
        List<ProdTecRoutProc> lines = service.list(ProdTecRoutProc.class, criteria);
        return Result.OK(lines);
    }

    @GetMapping("page")
    @Operation(summary = "产品工艺路线明细列表", description = "获取产品工艺路线明细列表（分页）", method = "GET")
    public Result<Page<ProdTecRoutProc>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) throws UnsupportedEncodingException {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<ProdTecRoutProc> lines = service.listPage(ProdTecRoutProc.class, page, criteria);
        return Result.OK(lines);
    }

    @GetMapping("list/{routId}")
    @Operation(summary = "根据routId获取产品工艺路线明细", description = "根据routId获取产品工艺路线明细", method = "GET")
    public Result<List<ProdTecRoutProc>> listByBizNo(@Parameter(description="业务单号") @PathVariable(name = "routId", required = true) String routId) {
        //Criteria c = Criteria.create().addCriterion("routId", Operator.EQ, routId);
        List<ProdTecRoutProc> lines = service.listByVersion(routId);
        return Result.OK(lines);
    }
}
